"""myproject URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import path

from django.conf.urls.static import static
from django.conf import settings

from django.views.generic import TemplateView

# 测试静态文件


def demostatic(request):
    return render(request, 'statictest.html')


# 测试媒体文件
def demomedia(request):
    return render(request, 'mediatest.html')


# 测试日志配置
def demologging(request):
    import logging
    logger = logging.getLogger('django')
    logger.info('测试日志配置')
    return HttpResponse('200')


# 检验redis设置是否成功
# https://django-redis-chs.readthedocs.io/zh_CN/latest/

urlpatterns = [
    path('admin/', admin.site.urls),
    path('demologging/', demologging),
    path('demostatic/', demostatic),
    path('demomedia/', demomedia),
    path('', TemplateView.as_view(template_name='index.html'))
]

# 开发环境下服务媒体文件,生产环境下可以使用Nginx
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
